package com.jmy.controller;

import com.jmy.pageresult.PageResult;
import com.jmy.pojo.Roles;
import com.jmy.service.RolesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: VE
 * @DATE: 2022/9/28 9:59
 * 描述:
 */
@RestController
public class RolesController {

    @Autowired
    private RolesService rolesService;

    @GetMapping("roles")
    public PageResult getRolesList(){
        List<Roles> rolesList = rolesService.getRolesList();
        return PageResult.success("获取成功",rolesList);
    }

    @GetMapping("roles/{aid}")
    public PageResult getRolesListByAdmin(@PathVariable("aid") Integer aid){
        List<Roles> rolesList = rolesService.getRolesListByAid(aid);
        List<Integer> ridList = new ArrayList<>();
        for (Roles r: rolesList) {
            ridList.add(r.getId()) ;
        }
        return PageResult.success("获取成功",ridList);
    }
}
